package cn.com.baiwei.controller;

import cn.com.baiwei.pojo.OrderForm;
import cn.com.baiwei.service.impl.OrderFormServiceImpl;
import io.swagger.annotations.*;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (OrderForm)表控制层
 *
 * @author vv
 * @since 2021-09-17 10:22:07
 * @version 1.0
 */
@RestController
@RequestMapping("/orderForm")
@Api(value = "(订单)管理",tags = "(订单)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class OrderFormController {
    /**
     * 服务对象
     */
    @Resource
    private OrderFormServiceImpl orderFormServiceImpl;

    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @param name  模糊查询的内容
     * @return 单条数据
     */
    @RequestMapping(value = "/selectOrderFormForPage", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "name",value = "**名称",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> selectOrderFormForPage(@RequestParam(name = "page") int index, String name) {
        return this.orderFormServiceImpl.selectOrderFormForPage(index, name);
    }

    /**
     * 查询所有数据
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有数据接口",notes = "查询所有数据接口",httpMethod = "GET")
    public Map<String, Object> selectAll() {
        return this.orderFormServiceImpl.selectAll();
    }

    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteOrderFormById", method = RequestMethod.POST)
    @ApiOperation(value = "根据订单id删除订单的接口",notes = "根据订单id删除订单的接口",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> deleteById(@RequestParam("id") String id) {
        return this.orderFormServiceImpl.deleteOrderFormById(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectOrderFormById", method = RequestMethod.GET)
    @ApiOperation(value = "通过订单id查询订单的接口",notes = "通过订单id查询订单的接口",httpMethod = "GET")
    public Map<String, Object> selectOrderFormById(Integer id) {
        return this.orderFormServiceImpl.selectOrderFormById(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param state 订单支付状态
     * @return 实例对象
     */
    @RequestMapping(value = "/selectOrderFormByState", method = RequestMethod.GET)
    @ApiOperation(value = "通过支付状态查询订单的接口",notes = "通过支付状态查询订单的接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "state",value = "支付状态(0为未支付1为已支付)",paramType = "query",dataType = "String",required = true),
    })
    public Map<String, Object> selectOrderFormByState(Integer state) {
        return this.orderFormServiceImpl.selectOrderFormByState(state);
    }

    /**
     * 通过主键更新单条数据
     *
     * @param orderForm 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateOrderFormById", method = RequestMethod.POST)
    @ApiOperation(value = "通过订单id修改一个订单的接口",notes = "通过订单id修改一个订单的接口",httpMethod = "POST")
    public Map<String, Object> updateOrderFormById(@RequestBody @ApiParam(name = "orderForm",value = "pojo模型",required = true) OrderForm orderForm) {
        return this.orderFormServiceImpl.updateOrderFormById(orderForm);
    }

    /**
     * 通过订单id修改支付状态(结账)
     *
     * @param orderForm 订单对象
     * @return 单条数据
     */
    @Transactional
    @RequestMapping(value = "/updateStateById", method = RequestMethod.POST)
    @ApiOperation(value = "通过订单id修改支付状态为已支付",notes = "通过订单id修改支付状态为已支付",httpMethod = "POST")
    public Map<String, Object> updateStateById(@RequestBody @ApiParam(name = "orderForm",value = "pojo模型",required = true) OrderForm orderForm) {
        return this.orderFormServiceImpl.updateStateById(orderForm);
    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param orderForm 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @Transactional
    @RequestMapping(value = "/insertOrderForm", method = RequestMethod.POST)
    @ApiOperation(value = "新增一个订单同时生成订单详情",notes = "新增一个订单同时生成订单详情",httpMethod = "POST")
    public Map<String, Object> insertOrderForm(@RequestBody @ApiParam(name = "orderForm",value = "pojo模型",required = true) OrderForm orderForm) {
        return this.orderFormServiceImpl.insertOrderForm(orderForm);
    }

}